﻿using GN.Pay.Client.Request.Trade;
using GN.Pay.Client.Response.Trade;
using GN.Pay.Client.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Client.Services
{
    /// <summary>
    /// 交易查询服务
    /// </summary>
    class TradeQueryService : APayService, ITradeQueryService
    {
        /// <summary>
        /// 
        /// </summary>
        private const string QueryPayApply_Service = "Trade.Query.Pay.Apply";
        /// <summary>
        /// 查询交易通道
        /// </summary>
        private const string Trade_Query_TradeChannel = "Trade.Query.TradeChannel";

        /// <summary>
        /// 查询交易订单
        /// </summary>
        private const string Trade_Query_Order = "Trade.Query.Order";

        /// <summary>
        /// 同步交易支付通道
        /// </summary>
        public const string Trade_Syn_Channel_Pay = "Trade.Syn.Channel.Pay";


        public TradeQueryService(IServiceClient client) 
            : base(client)
        {
        }

        /// <summary>
        /// 查询支付申请
        /// </summary>
        /// <param name="applyId"></param>
        /// <returns></returns>
        public PayApplyResponse QueryPayApply(string applyId)
        {
            ExceptionUtils.CheckNotNullOrNotWhiteSpace(applyId, nameof(applyId));
            return this.Client.CallService<PayApplyKeyRequest, PayApplyResponse>(QueryPayApply_Service, new PayApplyKeyRequest() { ApplyId = applyId });
        }

        /// <summary>
        /// 交易通道查询
        /// </summary>
        /// <param name="channelType">通道类型</param>
        /// <returns></returns>
        public List<TradeChannelResponse> TradeChannelQuery(ChannelType channelType)
        {
            return this.Client.CallService<TradeChannelRequest, List<TradeChannelResponse>>(Trade_Query_TradeChannel, new TradeChannelRequest() { ChannelType = channelType });
        }

        /// <summary>
        /// 交易订单查询
        /// </summary>
        /// <param name="orderNo">订单号</param>
        /// <returns></returns>
        public OrderQueryResponse TradeOrderQuery(string orderNo)
        {
            ExceptionUtils.CheckNotNullOrNotWhiteSpace(orderNo, nameof(orderNo));
            return this.Client.CallService<OrderRequest, OrderQueryResponse>(Trade_Query_Order, new OrderRequest() { OrderNo = orderNo });
        }

        /// <summary>
        /// 同步交易支付通道
        /// </summary>
        /// <param name="orderNo">订单号</param>
        /// <returns></returns>
        public SynTradePayChannelResponse SynTradePayChannel(string orderNo)
        {
            ExceptionUtils.CheckNotNullOrNotWhiteSpace(orderNo, nameof(orderNo));
            return this.Client.CallService<OrderRequest, SynTradePayChannelResponse>(Trade_Syn_Channel_Pay, new OrderRequest() { OrderNo = orderNo });
        }
    }
}
